const fs = require("fs");
const puppeteer = require("puppeteer");

(async () => {
 const cookies=[
    {
        "domain": ".taobao.com",
        "expirationDate": 1616204044.485831,
        "hostOnly": false,
        "httpOnly": false,
        "name": "_cc_",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "V32FPkk%2Fhw%3D%3D",
        "id": 1
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1585033372.513325,
        "hostOnly": false,
        "httpOnly": false,
        "name": "_m_h5_tk",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "6fdca053c6f68ec936061cbab6077233_1584437931686",
        "id": 2
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1585033372.513391,
        "hostOnly": false,
        "httpOnly": false,
        "name": "_m_h5_tk_enc",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "cb9fabf07d8563b025220a6c16d46385",
        "id": 3
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": true,
        "name": "_samesite_flag_",
        "path": "/",
        "sameSite": "unspecified",
        "secure": true,
        "session": true,
        "storeId": "0",
        "value": "true",
        "id": 4
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": false,
        "name": "_tb_token_",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "e5ebee4b35ea3",
        "id": 5
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1899259617,
        "hostOnly": false,
        "httpOnly": false,
        "name": "cna",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "BzN5FA+R5GMCASrszcxFIwce",
        "id": 6
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": true,
        "name": "cookie2",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "1304dc13f7cae601e13898a0fc9c14ea",
        "id": 7
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": false,
        "name": "csg",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "10c6686f",
        "id": 8
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": false,
        "name": "dnk",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "sleep_taobao",
        "id": 9
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1898322321.447687,
        "hostOnly": false,
        "httpOnly": true,
        "name": "enc",
        "path": "/",
        "sameSite": "no_restriction",
        "secure": true,
        "session": false,
        "storeId": "0",
        "value": "nnHugQxoV6OS%2BWqWs1VlThokFlMdZLE58iUWRA%2BLej5tbgdM0qv%2B2v3mie3BN9zV%2FdGG%2BrfI94Lx4wcHBQ5Rfw%3D%3D",
        "id": 10
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": false,
        "name": "existShop",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "MTU4NDY2ODA0NA%3D%3D",
        "id": 11
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1600254088,
        "hostOnly": false,
        "httpOnly": false,
        "name": "isg",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "BBwcrMPLrltQoF8PVEdw09Hh7TrOlcC_Sw-u6vYdNIfoQbzLHqZ2TjXzpam5SfgX",
        "id": 12
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1600254088,
        "hostOnly": false,
        "httpOnly": false,
        "name": "l",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "dBShp0Jnv34OGsZQKOCiIZdPZBQTQIRAguWA44jWi_5Iy1YsmBXOozprwev6cjWftvYB4zFVd1J9-etkiRRgTBH8sxAJtxDc.",
        "id": 13
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1587260044.485551,
        "hostOnly": false,
        "httpOnly": false,
        "name": "lgc",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "sleep_taobao",
        "id": 14
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1629703750.260135,
        "hostOnly": false,
        "httpOnly": false,
        "name": "miid",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "705398721252165504",
        "id": 15
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1585273132.55633,
        "hostOnly": false,
        "httpOnly": false,
        "name": "mt",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "ci=30_1",
        "id": 16
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1616204044.485985,
        "hostOnly": false,
        "httpOnly": true,
        "name": "sgcookie",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "EsgqnyRm5LYaS7UYKILTT",
        "id": 17
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": true,
        "name": "skt",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "ef0de493bf236f17",
        "id": 18
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1592444044.485576,
        "hostOnly": false,
        "httpOnly": false,
        "name": "t",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "83341fa90e47c6d9d48c350369ea75fe",
        "id": 19
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1600220040,
        "hostOnly": false,
        "httpOnly": false,
        "name": "tfstk",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "c83hB01FeDrBHKIPcMaINsbMRT-AZuxUd4uZ72XwG8ZuOu0NiVjN0dLJsJHnyg1..",
        "id": 20
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1637899614.208978,
        "hostOnly": false,
        "httpOnly": false,
        "name": "tg",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "0",
        "id": 21
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1614498280.546009,
        "hostOnly": false,
        "httpOnly": false,
        "name": "thw",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "cn",
        "id": 22
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1616204044.48574,
        "hostOnly": false,
        "httpOnly": false,
        "name": "tracknick",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "sleep_taobao",
        "id": 23
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": false,
        "name": "uc1",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "cookie14=UoTUPvbKhX9MOQ%3D%3D&cookie16=Vq8l%2BKCLySLZMFWHxqs8fwqnEw%3D%3D&cookie21=URm48syIYn73&pas=0&existShop=false",
        "id": 24
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1587260044.485502,
        "hostOnly": false,
        "httpOnly": true,
        "name": "uc3",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "lg2=U%2BGCWk%2F75gdr5Q%3D%3D&id2=UoCIRZ07e0JyYQ%3D%3D&nk2=EFIHyJq62%2FjeujBb&vt3=F8dBxd9kpeh3LeQrAkE%3D",
        "id": 25
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1587260044.485694,
        "hostOnly": false,
        "httpOnly": true,
        "name": "uc4",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "nk4=0%40EousInOzBOetHVULqjwWOJR0PSWXH3I%3D&id4=0%40UOg0Nzt%2FQfWISgIO2oh%2FX3bKqos0",
        "id": 26
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1592962679,
        "hostOnly": false,
        "httpOnly": false,
        "name": "UM_distinctid",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "16f3ab41b8a49d-0e01023d6a233a-5e4f281b-144000-16f3ab41b8b529",
        "id": 27
    },
    {
        "domain": ".taobao.com",
        "hostOnly": false,
        "httpOnly": false,
        "name": "v",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": true,
        "storeId": "0",
        "value": "0",
        "id": 28
    },
    {
        "domain": ".taobao.com",
        "expirationDate": 1602564247,
        "hostOnly": false,
        "httpOnly": false,
        "name": "x",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0",
        "id": 29
    },
    {
        "domain": "item.taobao.com",
        "expirationDate": 1870856459,
        "hostOnly": true,
        "httpOnly": false,
        "name": "_uab_collina",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "155549645945965874598751",
        "id": 30
    },
    {
        "domain": "item.taobao.com",
        "expirationDate": 1592038363,
        "hostOnly": true,
        "httpOnly": false,
        "name": "_umdata",
        "path": "/",
        "sameSite": "unspecified",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "G9AF1E622CB346A7FB7C0F3B4EB02E165FE0A06",
        "id": 31
    }
    ];
  //const url ="https://www.baidu.com";
  const url = "https://item.taobao.com/item.htm?spm=a230r.1.14.37.5ae82fa2UfTXKC&id=562989888178";
  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage();
  await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');
  await page.goto(url);
  await Promise.all(cookies.map(pair=>{
    return page.setCookie(pair)
}))
  await page.reload();

  let title = await page.$eval("#J_Title h3",el => el.innerText);
  console.log('===============');
  console.log(title);
  console.log('===============');
  
  page.waitForSelector('#J_PromoPriceNum'); //等待元素加载之后，否则获取不到异步加载的元
  let price = await page.$eval("#J_PromoPriceNum",el => el.innerText);

  console.log(price);
  console.log('===============');

  await page.waitFor(5000);
  await browser.close();
  
})().catch(error =>{console.log('error')});
